﻿
namespace SPContrib.Extensions
{
    /// <summary>
    /// Extensions for generic types
    /// </summary>
    public static class GenericExtensions
    {
        /// <summary>
        /// Indicates if the instance of T has a value (i.e. a more intelligent null reference check)
        /// </summary>
        /// <typeparam name="T">an example would be "somestring".HasValue&lt;string&gt;</typeparam>
        public static bool HasValue<T>(this T instance)
        {
            return instance.HasValue<T>(default(T));
        }

        /// <summary>
        /// Indicates if the instance of T has a value (i.e. a more intelligent null reference check) or some other default value that you supply
        /// </summary>
        /// <typeparam name="T">an example would be "somestring".HasValue&lt;string&gt;</typeparam>
        /// <param name="value">an example would be "someothervalue" if checking strings"</param>
        public static bool HasValue<T>(this T instance, T value)
        {
            return object.Equals(instance, value) == false;
        }
        
    }
}
